﻿using B.S.BaseData.Domain.Entities;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Read.API.Command.ApplyCommand;
using B.S.BaseData.Read.API.Command.MenuCommand;
using B.S.BaseData.Read.API.Command.RoleCommand;
using B.S.BaseData.Read.API.Command.UserCommand;
using B.S.BaseData.Read.API.DTO;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;


namespace B.S.BaseData.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mediator"></param>
        public UserController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIPaging<UserDTO>> GetUser([FromQuery] GetUserCommand request)
        {
            return mediator.Send(request);

        }
        /// <summary>
        /// 获取用户
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<User>> GetUsers([FromQuery] GetUsersCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取角色
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<RoleDTO>>> QueryRole([FromQuery] QueryRoleCommand request)
        {
            return mediator.Send(request);

        }
        /// <summary>
        /// 获取用户部门
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<EmpDTO>>> QueryEmp([FromQuery] QueryEmpCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取角色用户
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<RUDTO>>> QueryRoleUser([FromQuery]QueryRoleUserCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取菜单(下拉框使用)
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<MenuManagement>>> GetMenuSelect([FromQuery]MenuSelectCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取菜单列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<APIPaging<MenuDTO>>> GetMenu([FromQuery]MenuQueryCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<MenuManagement>>> GetIdDel([FromQuery]SelectIdDelCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取角色树
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Role>>> GetRoleTree([FromQuery] GetRoleTreeCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取菜单树
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<CaseMenuDTO>>> GetMenuTree([FromQuery] GetMenuCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回受影响行数</returns>
        [HttpGet]
        public async Task<APIResult<User>> Login([FromQuery]UserLoginCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 反填获取菜单(名称,id)
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<APIResult<List<RoleMenu>>> GetMenuNameFanTian([FromQuery]GetFanTianCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 权重取值
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<User>>> GetAppBy([FromQuery]GetAppByCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 请假列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<APIPaging<Apply>>> GetApplyList([FromQuery]ApplyQueryCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 反填申请人信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Apply>>> FanApplyId([FromQuery]GetAppBYIdCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
